<?php

require_once "objetos/Usuario.php";
require_once "server/EmailServer.php";

$destinatario = $_POST["destinatario"];
$assunto = $_POST["assunto"];
$conteudo = $_POST["conteudo"];

session_start();
if (!array_key_exists("userId", $_SESSION) && $_SESSION["userId"] == NULL) {
    header("Location: ../index.php");
}
$userId = $_SESSION["userId"];
$emailServer = new EmailServer();

$connRascunho = $emailServer->imapOpenRascunho($userId->getLogin(), $userId->getSenha());
$message = "From: ".$userId->getLogin()."\r\n"
           ."To: ".$destinatario."\r\n"
           ."Subject: ".$assunto."\r\n"
           ."\r\n"
           .$conteudo."\r\n";
$resposta = imap_append($connRascunho, "{127.0.0.1}RASCUNHO", $message);
$emailServer->imapClose($connRascunho);

header("Location: ../paginas/novoEmail.php?rascunho=1");


?>
